package com.wchat.controller;

import com.wchat.bean.entity.Users;
import com.wchat.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author : willian fu
 * @date : 2021/8/24
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 登录
     * @param username 手机号/账号
     * @param password 密码
     * @return 登录结果
     */
    @GetMapping("login")
    public Object login(@RequestParam String username, @RequestParam String password){
        return userService.login(username, password);
    }

    /**
     * 注册
     * @param mobile 手机号
     * @param avatar 头像
     * @param username 账号
     * @param password 密码
     * @return 注册结果
     */
    @PostMapping("register")
    public Object userRegister(@RequestParam String mobile, @RequestParam(required = false) String avatar,
                           @RequestParam String username, @RequestParam String password){
        return userService.userRegister(mobile, username, avatar, password);
    }

    @PutMapping("password")
    public Object updatePassword(@RequestParam String oldPsw, @RequestParam String newPsw){
        return userService.updatePassword(oldPsw, newPsw);
    }

    /**
     * 根据用户id查询信息
     * @param userId 用户id
     * @return
     */
    @GetMapping("info")
    public Object getUserInfoById(Integer userId){
        return userService.getUserInfoById(userId);
    }

    /**
     * 修改个人信息
     * @param user 信息
     * @return 修改结果
     */
    @PutMapping
    public Object updateInfo(@RequestBody Users user){
        return userService.updateInfo(user);
    }
}
